//
//  CommentFrame.m
//  MoneyApp
//
//  Created by leiyifan on 2017/2/20.
//  Copyright © 2017年 leiyifan. All rights reserved.
//

#import "CommentFrame.h"


@implementation CommentFrame

-(void)setCommentModel:(CommentModel *)commentModel{
    _commentModel = commentModel;
    _headImageFrame = CGRectMake(14, 17, 36, 36);
    _nickNameFrame = CGRectMake(14+36+14, 17, LLScreenWidth - (14+36+14+84), 14);
    _timeFrame = CGRectMake(14+36+14, 17+14+5, 200, 12);
    _zanCountFrame = CGRectMake(LLScreenWidth - 14- 42, 17, 42, 21);
    CGFloat wordH = [self getSpaceLabelHeight:commentModel.txt1 withFont:[UIFont systemFontOfSize:14] withWidth:LLScreenWidth - (14+36+14*2)]+8;
    
    _commentFrame = CGRectMake(14+36+14, 17+36+10, LLScreenWidth - (14+36+14*2), wordH);
    
    CGFloat answerH = 0;
     if (self.commentModel.comm.count != 0) {
           NSString *reText = [NSString stringWithFormat:@"%@ : %@",commentModel.reNickName,commentModel.retxt];
         answerH = [self getSpaceLabelHeight:reText  withFont:[UIFont systemFontOfSize:12] withWidth:LLScreenWidth - (14+36+14*2)]+8;
         _answerViewFrame = CGRectMake(14+36+14, 17+36+10+wordH+8, LLScreenWidth - (14+36+14*2), answerH);
     }

    _pageLineFrame = CGRectMake(0, 17+36+10+wordH+17+answerH, LLScreenWidth, 0.5);
    _rowHeight =17+36+10+wordH+17+0.5+answerH;
}

//计算UILabel的高度(带有行间距的情况)

-(CGFloat)getSpaceLabelHeight:(NSString*)str withFont:(UIFont*)font withWidth:(CGFloat)width {
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
    paraStyle.alignment = NSTextAlignmentJustified;
    paraStyle.lineSpacing = 10;
//    paraStyle.hyphenationFactor = 1.0;
//    paraStyle.firstLineHeadIndent = 8.0;
    paraStyle.paragraphSpacingBefore = 0.0;
    paraStyle.allowsDefaultTighteningForTruncation = YES;
    paraStyle.headIndent = 0;
    paraStyle.tailIndent = 0;
    NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@0.f
                          };
    
    CGSize size = [str boundingRectWithSize:CGSizeMake(width, LLScreenHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
    return size.height;
}
@end
